/**
* @file acl_rt_impl.h
*
* Copyright (c) Huawei Technologies Co., Ltd. 2025. All Rights reserved.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

#ifndef RUNTIME_ACL_RT_IMPL_H_
#define RUNTIME_ACL_RT_IMPL_H_

#include <stdint.h>
#include <stddef.h>
#include "acl_rt.h"
#include "acl_base.h"

#ifdef __cplusplus
extern "C" {
#endif

ACL_FUNC_VISIBILITY aclError aclrtPeekAtLastErrorImpl(aclrtLastErrLevel level);

ACL_FUNC_VISIBILITY aclError aclrtGetLastErrorImpl(aclrtLastErrLevel level);

ACL_FUNC_VISIBILITY aclError aclrtSetExceptionInfoCallbackImpl(aclrtExceptionInfoCallback callback);

ACL_FUNC_VISIBILITY uint32_t aclrtGetTaskIdFromExceptionInfoImpl(const aclrtExceptionInfo *info);

ACL_FUNC_VISIBILITY uint32_t aclrtGetStreamIdFromExceptionInfoImpl(const aclrtExceptionInfo *info);

ACL_FUNC_VISIBILITY uint32_t aclrtGetThreadIdFromExceptionInfoImpl(const aclrtExceptionInfo *info);

ACL_FUNC_VISIBILITY uint32_t aclrtGetDeviceIdFromExceptionInfoImpl(const aclrtExceptionInfo *info);

ACL_FUNC_VISIBILITY uint32_t aclrtGetErrorCodeFromExceptionInfoImpl(const aclrtExceptionInfo *info);

ACL_FUNC_VISIBILITY aclError aclrtSubscribeReportImpl(uint64_t threadId, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtLaunchCallbackImpl(aclrtCallback fn, void *userData,
    aclrtCallbackBlockType blockType, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtProcessReportImpl(int32_t timeout);

ACL_FUNC_VISIBILITY aclError aclrtUnSubscribeReportImpl(uint64_t threadId, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtCreateContextImpl(aclrtContext *context, int32_t deviceId);

ACL_FUNC_VISIBILITY aclError aclrtDestroyContextImpl(aclrtContext context);

ACL_FUNC_VISIBILITY aclError aclrtSetCurrentContextImpl(aclrtContext context);

ACL_FUNC_VISIBILITY aclError aclrtGetCurrentContextImpl(aclrtContext *context);

ACL_FUNC_VISIBILITY aclError aclrtCtxGetSysParamOptImpl(aclSysParamOpt opt, int64_t *value);

ACL_FUNC_VISIBILITY aclError aclrtCtxSetSysParamOptImpl(aclSysParamOpt opt, int64_t value);

ACL_FUNC_VISIBILITY aclError aclrtGetSysParamOptImpl(aclSysParamOpt opt, int64_t *value);

ACL_FUNC_VISIBILITY aclError aclrtSetSysParamOptImpl(aclSysParamOpt opt, int64_t value);

ACL_FUNC_VISIBILITY aclError aclrtSetDeviceImpl(int32_t deviceId);

ACL_FUNC_VISIBILITY aclError aclrtResetDeviceImpl(int32_t deviceId);

ACL_FUNC_VISIBILITY aclError aclrtResetDeviceForceImpl(int32_t deviceId);

ACL_FUNC_VISIBILITY aclError aclrtGetDeviceImpl(int32_t *deviceId);

ACL_FUNC_VISIBILITY aclError aclrtSetStreamFailureModeImpl(aclrtStream stream, uint64_t mode);

ACL_FUNC_VISIBILITY aclError aclrtGetRunModeImpl(aclrtRunMode *runMode);

ACL_FUNC_VISIBILITY aclError aclrtSynchronizeDeviceImpl(void);

ACL_FUNC_VISIBILITY aclError aclrtSynchronizeDeviceWithTimeoutImpl(int32_t timeout);

ACL_FUNC_VISIBILITY aclError aclrtSetTsDeviceImpl(aclrtTsId tsId);

ACL_FUNC_VISIBILITY aclError aclrtGetDeviceUtilizationRateImpl(int32_t deviceId, aclrtUtilizationInfo *utilizationInfo);

ACL_FUNC_VISIBILITY aclError aclrtGetDeviceCountImpl(uint32_t *count);

ACL_FUNC_VISIBILITY aclError aclrtCreateEventImpl(aclrtEvent *event);

ACL_FUNC_VISIBILITY aclError aclrtCreateEventWithFlagImpl(aclrtEvent *event, uint32_t flag);

ACL_FUNC_VISIBILITY aclError aclrtCreateEventExWithFlagImpl(aclrtEvent *event, uint32_t flag);

ACL_FUNC_VISIBILITY aclError aclrtDestroyEventImpl(aclrtEvent event);

ACL_FUNC_VISIBILITY aclError aclrtRecordEventImpl(aclrtEvent event, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtResetEventImpl(aclrtEvent event, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtQueryEventImpl(aclrtEvent event, aclrtEventStatus *status);

ACL_FUNC_VISIBILITY aclError aclrtQueryEventStatusImpl(aclrtEvent event, aclrtEventRecordedStatus *status);

ACL_FUNC_VISIBILITY aclError aclrtQueryEventWaitStatusImpl(aclrtEvent event, aclrtEventWaitStatus *status);

ACL_FUNC_VISIBILITY aclError aclrtSynchronizeEventImpl(aclrtEvent event);

ACL_FUNC_VISIBILITY aclError aclrtSynchronizeEventWithTimeoutImpl(aclrtEvent event, int32_t timeout);

ACL_FUNC_VISIBILITY aclError aclrtEventElapsedTimeImpl(float *ms, aclrtEvent startEvent, aclrtEvent endEvent);

ACL_FUNC_VISIBILITY aclError aclrtEventGetTimestampImpl(aclrtEvent event, uint64_t *timestamp);

ACL_FUNC_VISIBILITY aclError aclrtMallocImpl(void **devPtr, size_t size, aclrtMemMallocPolicy policy);

ACL_FUNC_VISIBILITY aclError aclrtMallocAlign32Impl(void **devPtr, size_t size, aclrtMemMallocPolicy policy);

ACL_FUNC_VISIBILITY aclError aclrtMallocCachedImpl(void **devPtr, size_t size, aclrtMemMallocPolicy policy);

ACL_FUNC_VISIBILITY aclError aclrtMallocWithCfgImpl(void **devPtr, size_t size, aclrtMemMallocPolicy policy,
    aclrtMallocConfig *cfg);

ACL_FUNC_VISIBILITY aclError aclrtMallocForTaskSchedulerImpl(void **devPtr, size_t size, aclrtMemMallocPolicy policy,
    aclrtMallocConfig *cfg);

ACL_FUNC_VISIBILITY aclError aclrtMallocHostWithCfgImpl(void **ptr, uint64_t size, aclrtMallocConfig *cfg);

ACL_FUNC_VISIBILITY aclError aclrtPointerGetAttributesImpl(const void *ptr, aclrtPtrAttributes *attributes);

ACL_FUNC_VISIBILITY aclError aclrtHostRegisterImpl(void *ptr, uint64_t size, aclrtHostRegisterType type, void **devPtr);

ACL_FUNC_VISIBILITY aclError aclrtHostUnregisterImpl(void *ptr);

ACL_FUNC_VISIBILITY aclError aclrtGetThreadLastTaskIdImpl(uint32_t *taskId);

ACL_FUNC_VISIBILITY aclError aclrtStreamGetIdImpl(aclrtStream stream, int32_t *streamId);

ACL_FUNC_VISIBILITY aclError aclrtMemFlushImpl(void *devPtr, size_t size);

ACL_FUNC_VISIBILITY aclError aclrtMemInvalidateImpl(void *devPtr, size_t size);

ACL_FUNC_VISIBILITY aclError aclrtFreeImpl(void *devPtr);

ACL_FUNC_VISIBILITY aclError aclrtMallocHostImpl(void **hostPtr, size_t size);

ACL_FUNC_VISIBILITY aclError aclrtFreeHostImpl(void *hostPtr);

ACL_FUNC_VISIBILITY aclError aclrtMemcpyImpl(void *dst, size_t destMax, const void *src, size_t count,
    aclrtMemcpyKind kind);

ACL_FUNC_VISIBILITY aclError aclrtMemsetImpl(void *devPtr, size_t maxCount, int32_t value, size_t count);

ACL_FUNC_VISIBILITY aclError aclrtMemcpyAsyncImpl(void *dst, size_t destMax, const void *src, size_t count,
    aclrtMemcpyKind kind, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtMemcpyAsyncWithConditionImpl(void *dst, size_t destMax, const void *src,
    size_t count, aclrtMemcpyKind kind, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtMemcpy2dImpl(void *dst, size_t dpitch, const void *src, size_t spitch,
    size_t width, size_t height, aclrtMemcpyKind kind);

ACL_FUNC_VISIBILITY aclError aclrtMemcpy2dAsyncImpl(void *dst, size_t dpitch, const void *src, size_t spitch,
    size_t width, size_t height, aclrtMemcpyKind kind, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtMemsetAsyncImpl(void *devPtr, size_t maxCount, int32_t value, size_t count,
    aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtReserveMemAddressImpl(void **virPtr, size_t size, size_t alignment, void *expectPtr,
    uint64_t flags);

ACL_FUNC_VISIBILITY aclError aclrtReleaseMemAddressImpl(void *virPtr);

ACL_FUNC_VISIBILITY aclError aclrtMallocPhysicalImpl(aclrtDrvMemHandle *handle, size_t size,
    const aclrtPhysicalMemProp *prop, uint64_t flags);

ACL_FUNC_VISIBILITY aclError aclrtFreePhysicalImpl(aclrtDrvMemHandle handle);

ACL_FUNC_VISIBILITY aclError aclrtMapMemImpl(void *virPtr, size_t size, size_t offset, aclrtDrvMemHandle handle,
    uint64_t flags);

ACL_FUNC_VISIBILITY aclError aclrtUnmapMemImpl(void *virPtr);

ACL_FUNC_VISIBILITY aclError aclrtCreateStreamImpl(aclrtStream *stream);

ACL_FUNC_VISIBILITY aclError aclrtCreateStreamWithConfigImpl(aclrtStream *stream, uint32_t priority, uint32_t flag);

ACL_FUNC_VISIBILITY aclError aclrtDestroyStreamImpl(aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtDestroyStreamForceImpl(aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtSynchronizeStreamImpl(aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtSynchronizeStreamWithTimeoutImpl(aclrtStream stream, int32_t timeout);

ACL_FUNC_VISIBILITY aclError aclrtStreamQueryImpl(aclrtStream stream, aclrtStreamStatus *status);

ACL_FUNC_VISIBILITY aclError aclrtStreamWaitEventImpl(aclrtStream stream, aclrtEvent event);

ACL_FUNC_VISIBILITY aclError aclrtSetGroupImpl(int32_t groupId);

ACL_FUNC_VISIBILITY aclError aclrtGetGroupCountImpl(uint32_t *count);

ACL_FUNC_VISIBILITY aclrtGroupInfo *aclrtCreateGroupInfoImpl();

ACL_FUNC_VISIBILITY aclError aclrtDestroyGroupInfoImpl(aclrtGroupInfo *groupInfo);

ACL_FUNC_VISIBILITY aclError aclrtGetAllGroupInfoImpl(aclrtGroupInfo *groupInfo);

ACL_FUNC_VISIBILITY aclError aclrtGetGroupInfoDetailImpl(const aclrtGroupInfo *groupInfo, int32_t groupIndex,
    aclrtGroupAttr attr, void *attrValue, size_t valueLen, size_t *paramRetSize);

ACL_FUNC_VISIBILITY aclError aclrtDeviceCanAccessPeerImpl(int32_t *canAccessPeer, int32_t deviceId,
    int32_t peerDeviceId);

ACL_FUNC_VISIBILITY aclError aclrtDeviceEnablePeerAccessImpl(int32_t peerDeviceId, uint32_t flags);

ACL_FUNC_VISIBILITY aclError aclrtDeviceDisablePeerAccessImpl(int32_t peerDeviceId);

ACL_FUNC_VISIBILITY aclError aclrtGetMemInfoImpl(aclrtMemAttr attr, size_t *free, size_t *total);

ACL_FUNC_VISIBILITY aclError aclrtSetOpWaitTimeoutImpl(uint32_t timeout);

ACL_FUNC_VISIBILITY aclError aclrtSetOpExecuteTimeOutImpl(uint32_t timeout);

ACL_FUNC_VISIBILITY aclError aclrtSetOpExecuteTimeOutWithMsImpl(uint32_t timeout);

ACL_FUNC_VISIBILITY aclError aclrtSetStreamOverflowSwitchImpl(aclrtStream stream, uint32_t flag);

ACL_FUNC_VISIBILITY aclError aclrtGetStreamOverflowSwitchImpl(aclrtStream stream, uint32_t *flag);

ACL_FUNC_VISIBILITY aclError aclrtSetDeviceSatModeImpl(aclrtFloatOverflowMode mode);

ACL_FUNC_VISIBILITY aclError aclrtGetDeviceSatModeImpl(aclrtFloatOverflowMode *mode);

ACL_FUNC_VISIBILITY aclError aclrtGetOverflowStatusImpl(void *outputAddr, size_t outputSize, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtResetOverflowStatusImpl(aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtQueryDeviceStatusImpl(int32_t deviceId, aclrtDeviceStatus *deviceStatus);

ACL_FUNC_VISIBILITY aclrtBinary aclrtCreateBinaryImpl(const void *data, size_t dataLen);

ACL_FUNC_VISIBILITY aclError aclrtDestroyBinaryImpl(aclrtBinary binary);

ACL_FUNC_VISIBILITY aclError aclrtBinaryLoadImpl(const aclrtBinary binary, aclrtBinHandle *binHandle);

ACL_FUNC_VISIBILITY aclError aclrtBinaryUnLoadImpl(aclrtBinHandle binHandle);

ACL_FUNC_VISIBILITY aclError aclrtBinaryGetFunctionImpl(const aclrtBinHandle binHandle, const char *kernelName,
    aclrtFuncHandle *funcHandle);

ACL_FUNC_VISIBILITY aclError aclrtLaunchKernelImpl(aclrtFuncHandle funcHandle, uint32_t blockDim,
    const void *argsData, size_t argsSize, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtMemExportToShareableHandleImpl(aclrtDrvMemHandle handle,
    aclrtMemHandleType handleType, uint64_t flags, uint64_t *shareableHandle);

ACL_FUNC_VISIBILITY aclError aclrtMemImportFromShareableHandleImpl(uint64_t shareableHandle,
    int32_t deviceId, aclrtDrvMemHandle *handle);

ACL_FUNC_VISIBILITY aclError aclrtMemSetPidToShareableHandleImpl(uint64_t shareableHandle,
    int32_t *pid, size_t pidNum);

ACL_FUNC_VISIBILITY aclError aclrtMemGetAllocationGranularityImpl(aclrtPhysicalMemProp *prop,
    aclrtMemGranularityOptions option, size_t *granularity);

ACL_FUNC_VISIBILITY aclError aclrtDeviceGetBareTgidImpl(int32_t *pid);

ACL_FUNC_VISIBILITY aclError aclrtCmoAsyncImpl(void *src, size_t size, aclrtCmoType cmoType, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtGetMemUceInfoImpl(int32_t deviceId, aclrtMemUceInfo *memUceInfoArray,
    size_t arraySize, size_t *retSize);

ACL_FUNC_VISIBILITY aclError aclrtDeviceTaskAbortImpl(int32_t deviceId, uint32_t timeout);

ACL_FUNC_VISIBILITY aclError aclrtMemUceRepairImpl(int32_t deviceId, aclrtMemUceInfo *memUceInfoArray,
    size_t arraySize);

ACL_FUNC_VISIBILITY aclError aclrtStreamAbortImpl(aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtBinaryLoadFromFileImpl(const char* binPath, aclrtBinaryLoadOptions *options,
    aclrtBinHandle *binHandle);

ACL_FUNC_VISIBILITY aclError aclrtBinaryGetFunctionByEntryImpl(aclrtBinHandle binHandle, uint64_t funcEntry,
    aclrtFuncHandle *funcHandle);

ACL_FUNC_VISIBILITY aclError aclrtGetFunctionAddrImpl(aclrtFuncHandle funcHandle, void **aicAddr, void **aivAddr);

ACL_FUNC_VISIBILITY aclError aclrtGetMemcpyDescSizeImpl(aclrtMemcpyKind kind, size_t *descSize);

ACL_FUNC_VISIBILITY aclError aclrtSetMemcpyDescImpl(void *desc, aclrtMemcpyKind kind, void *srcAddr, void *dstAddr,
    size_t count, void *config);

ACL_FUNC_VISIBILITY aclError aclrtMemcpyAsyncWithDescImpl(void *desc, aclrtMemcpyKind kind, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtKernelArgsGetHandleMemSizeImpl(aclrtFuncHandle funcHandle, size_t *memSize);

ACL_FUNC_VISIBILITY aclError aclrtKernelArgsGetMemSizeImpl(aclrtFuncHandle funcHandle, size_t userArgsSize,
    size_t *actualArgsSize);

ACL_FUNC_VISIBILITY aclError aclrtKernelArgsInitImpl(aclrtFuncHandle funcHandle, aclrtArgsHandle *argsHandle);

ACL_FUNC_VISIBILITY aclError aclrtKernelArgsInitByUserMemImpl(aclrtFuncHandle funcHandle, aclrtArgsHandle argsHandle,
    void *userHostMem, size_t actualArgsSize);

ACL_FUNC_VISIBILITY aclError aclrtKernelArgsAppendImpl(aclrtArgsHandle argsHandle, void *param, size_t paramSize,
    aclrtParamHandle *paramHandle);

ACL_FUNC_VISIBILITY aclError aclrtKernelArgsAppendPlaceHolderImpl(aclrtArgsHandle argsHandle,
    aclrtParamHandle *paramHandle);

ACL_FUNC_VISIBILITY aclError aclrtKernelArgsGetPlaceHolderBufferImpl(aclrtArgsHandle argsHandle,
    aclrtParamHandle paramHandle, size_t dataSize, void **bufferAddr); 

ACL_FUNC_VISIBILITY aclError aclrtKernelArgsParaUpdateImpl(aclrtArgsHandle argsHandle, aclrtParamHandle paramHandle,
    void *param, size_t paramSize);

ACL_FUNC_VISIBILITY aclError aclrtLaunchKernelWithConfigImpl(aclrtFuncHandle funcHandle, uint32_t blockDim,
    aclrtStream stream, aclrtLaunchKernelCfg *cfg, aclrtArgsHandle argsHandle, void *reserve);

ACL_FUNC_VISIBILITY aclError aclrtKernelArgsFinalizeImpl(aclrtArgsHandle argsHandle);

ACL_FUNC_VISIBILITY aclError aclrtValueWriteImpl(void* devAddr, uint64_t value, uint32_t flag, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtValueWaitImpl(void* devAddr, uint64_t value, uint32_t flag, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtGetStreamAvailableNumImpl(uint32_t *streamCount);

ACL_FUNC_VISIBILITY aclError aclrtSetStreamAttributeImpl(aclrtStream stream, aclrtStreamAttr stmAttrType,
    aclrtStreamAttrValue *value);

ACL_FUNC_VISIBILITY aclError aclrtGetStreamAttributeImpl(aclrtStream stream, aclrtStreamAttr stmAttrType,
    aclrtStreamAttrValue *value);

ACL_FUNC_VISIBILITY aclError aclrtCreateNotifyImpl(aclrtNotify *notify, uint64_t flag);

ACL_FUNC_VISIBILITY aclError aclrtDestroyNotifyImpl(aclrtNotify notify);

ACL_FUNC_VISIBILITY aclError aclrtRecordNotifyImpl(aclrtNotify notify, aclrtStream stream);

ACL_FUNC_VISIBILITY aclError aclrtWaitAndResetNotifyImpl(aclrtNotify notify, aclrtStream stream, uint32_t timeout);

ACL_FUNC_VISIBILITY aclError aclrtGetNotifyIdImpl(aclrtNotify notify, uint32_t *notifyId);

ACL_FUNC_VISIBILITY aclError aclrtGetEventIdImpl(aclrtEvent event, uint32_t *eventId);

ACL_FUNC_VISIBILITY aclError aclrtGetEventAvailNumImpl(uint32_t *eventCount);

ACL_FUNC_VISIBILITY aclError aclrtGetDeviceInfoImpl(uint32_t deviceId, aclrtDevAttr attr, int64_t *value);

ACL_FUNC_VISIBILITY aclError aclrtDeviceGetStreamPriorityRangeImpl(int32_t *leastPriority, int32_t *greatestPriority);

ACL_FUNC_VISIBILITY aclError aclrtGetDeviceCapabilityImpl(int32_t deviceId, aclrtDevFeatureType devFeatureType,
    int32_t *value);

ACL_FUNC_VISIBILITY aclError aclrtCtxGetCurrentDefaultStreamImpl(aclrtStream *stream);

ACL_FUNC_VISIBILITY aclError aclrtReduceAsyncImpl(void *dst, const void *src, uint64_t count, aclrtReduceKind kind,
    aclDataType type, aclrtStream stream, void *reserve);

ACL_FUNC_VISIBILITY aclError aclrtSetDeviceWithoutTsdVXXImpl(int32_t deviceId);

ACL_FUNC_VISIBILITY aclError aclrtResetDeviceWithoutTsdVXXImpl(int32_t deviceId);

ACL_FUNC_VISIBILITY const char *aclrtGetSocNameImpl();

#ifdef __cplusplus
}
#endif

#endif // RUNTIME_ACL_RT_IMPL_H_
